<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html xmlns:th="" lang="zh-CN">
<%@include file="/WEB-INF/pages/base/include.jsp"%>
<body>
<div id="wrapper">
    <%@include file="/WEB-INF/pages/base/menu.jsp"%>
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h3 class="page-header">用户管理</h3>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12">
                <div class="panel panel-default">
                    <div class="panel-heading">总代理列表</div>
                    <div class="panel-body inner-body">
                        <div class="main-box-search">
                            <form method="post" name="from1" id="searchForm">
                                <div class="search-row">
                                    <input type="hidden" name="" value="">
                                    <div class="col-lg-2 col-md-6" style="margin-bottom:15px; padding-left:0px;">
                                        <input class="form-control" type="text" name="orderId" id="accountId"
                                               placeholder="请输入id查询">
                                    </div>
                                    <div class="col-lg-2 col-md-6" style=" margin-bottom:15px;">
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="dataTable_wrapper">
                            <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                <thead>
                                <tr>
                                	<th class="text-center" style="width:6%;">用户id</th>
                                    <th class="text-center" style="width:6%;">昵称</th>
                                    <th class="text-center" style="width:4%;">头像</th>
                                    <th class="text-center" style="width:4%;">操作</th>
                                </tr>
                                </thead>
                                <tbody  id="userList">
                                </tbody>
                            </table>
                        </div>
                        
                        <div class="modal fade" id="sendModel">
                            <div class="modal-dialog">
                                <div class="modal-content message_align">
                                    <div class="modal-header">
                                        <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">×</span>
                                        </button>
                                        <h4 class="modal-title">物流配送区域</h4>
                                    </div>
                                    <div class="modal-body">
                                        <div class="form-group" id="provinceDiv">
                                            <label class="col-lg-3 clo-md-3 text-right"
                                                   style="line-height:34px;">配送省份：</label>
                                            <div class="col-lg-6 col-md-6">
                                                <select class="form-control" id="provinceList" onchange="provinceChange()">
                                                </select>
                                            </div>
                                        </div>
                                        <div class="clearfix"></div>
                                        <div class="form-group" id="cityDiv">
                                            <label class="col-lg-3 clo-md-3 text-right"
                                                   style="line-height:34px;">配送市：</label>
                                            <div class="col-lg-6 col-md-6">
                                                <select class="form-control" id="cityList" onchange="cityChange()">
                                                </select>
                                            </div>
                                        </div>                                       
                                        <div class="clearfix"></div>
                                        <div class="form-group" id="districtDiv">
                                            <label class="col-lg-3 clo-md-3 text-right"
                                                   style="line-height:34px;">配送地区：</label>
                                            <div class="col-lg-6 col-md-6">
                                                <select class="form-control" id="districtList">
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="modal-footer">
                                        <input id="accountId_hidden" type="hidden">
                                        <button class="btn btn-default" type="button" data-dismiss="modal">取消</button>
                                        <a class="btn btn-danger" onclick="deliver_goods()" data-dismiss="modal">编辑</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="box">
							<div id="pagination3" class="page fl"></div>
						</div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
	searchCase(0,1);
	$('#searchForm').change(function(e) {
		searchCase(1,1);
	})
	//搜索微商
	function searchCase(flag,page) {
		var pageSize= 10;
		
		var accountId = null;
		
		if(flag == 1){
			accountId = $("#accountId").val();
		}
		
		var baseURL = "${webPath}/partner/list";
	    var json_package = {
	        "head": {},
	        "body": {
	        	"accountId": accountId,
	            "page": page,
	            "pageSize": pageSize
	        }
	    }
	    $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	        if (typeof result == 'string') result = JSON.parse(result);
	        if (result.body.result == '1') {
	            alert(result.body.description)
	            $("#userList").empty();
	        } else {
	        	$("#userList").empty();
	        	var list = result.body.list;
	        	var count = result.body.count;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<tr>';
	        		str += '	<td class="text-center">'+list[i].accountId+'</td>';
	        		str += '	<td class="text-center">'+list[i].nickname+'</td>';
	        		str += '	<td class="text-center"><img src="'+list[i].image+'" width="30px"></td>';
	        		str += '	<td class="text-center">';
					str += '		<button class="btn btn-default  deliver_goods" onclick=send('+list[i].accountId+')>物流配送范围</button>';
					str += '	</td>';
	        		str += '</tr>';
	        	}
	        	$("#userList").append(str);
	        	console.log(list);
	        	
	        	var currentPage = page;
	        	var sumPage = Math.ceil(count/pageSize);
	        	
	        	$("#pagination3").pagination({
					currentPage: currentPage,
					totalPage: sumPage,
					isShow: true,
					count: 10,
					homePageText: "首页",
					endPageText: "尾页",
					prevPageText: "上一页",
					nextPageText: "下一页",
					callback: function(current) {
						searchCase(1,current);
					}
				});
	        }
	    })
	}
	
	function send(accountId) {
        $('#sendModel').modal();
        $("#accountId_hidden").val(accountId);
        
        var baseURL = "${webPath}/partner/accountProvinceList";
        var accountId = $("#accountId_hidden").val();
        var json_package = {
            "head": {},
            "body": {"accountId": accountId}
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                console.log(result.body.list);
                
                $("#provinceList").empty();
	        	var list = result.body.list;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<option value="'+list[i].provinceId+'">'+list[i].name+'</option>';
	        	}
	        	$("#provinceList").append(str);
	        	
	        	///
	        	
	        	var provinceId = $("#provinceList").find("option:selected").val();
	        	baseURL = "${webPath}/partner/accountCityList";
	            json_package = {
	                "head": {},
	                "body": {"accountId": accountId,"provinceId":provinceId}
	            };
	            $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	                if (typeof result == 'string') result = JSON.parse(result);
	                if (result.body.result == '0') {
	                    
	                    $("#cityList").empty();
	    	        	var list = result.body.list;
	    	        	var str = "";
	    	        	if(list.length<=0){
	    	        		return
	    	        	}
	    	        	for(var i=0;i<list.length;i++){
	    	        		str += '<option value="'+list[i].cityId+'" name="'+list[i].isAll+'">'+list[i].name+'</option>';
	    	        	}
	    	        	$("#cityList").append(str);
	                    
	    	        	///
	    	        	
	    	        	var cityId = $("#cityList").find("option:selected").val();
	    	        	var isAll = $("#cityList").find("option:selected").attr("name");
	    		    	baseURL = "${webPath}/partner/accountDistrictList";
	    		        json_package = {
	    		            "head": {},
	    		            "body": {"accountId": accountId,"cityId":cityId,"isAll":isAll}
	    		        };
	    		        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
	    		            if (typeof result == 'string') result = JSON.parse(result);
	    		            if (result.body.result == '0') {
	    		                $("#districtList").empty();
	    			        	var list = result.body.list;
	    			        	var str = "";
	    			        	if(list.length<=0){
	    			        		return
	    			        	}
	    			        	for(var i=0;i<list.length;i++){
	    			        		str += '<option value="'+list[i].cityId+'">'+list[i].name+'</option>';
	    			        	}
	    			        	$("#districtList").append(str);
	    			        	console.log(list);
	    		            } else {
	    		                alert(result.body.description)
	    		            }
	    		        });
	                } else {
	                    alert(result.body.description)
	                }
	            });
            } else {
                alert(result.body.description)
            }
        })
        
    }
	
    function provinceChange(){
    	var provinceId = $("#provinceList").find("option:selected").val();
    	
    	var baseURL = "${webPath}/partner/accountCityList";
        var accountId = $("#accountId_hidden").val();
        var json_package = {
            "head": {},
            "body": {"accountId": accountId,"provinceId":provinceId}
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                
                $("#cityList").empty();
	        	var list = result.body.list;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<option value="'+list[i].cityId+'" name="'+list[i].isAll+'">'+list[i].name+'</option>';
	        	}
	        	$("#cityList").append(str);
                
	        	///
	        	
	        	var cityId = $("#cityList").find("option:selected").val();
	        	var isAll = $("#cityList").find("option:selected").attr("name");
		    	baseURL = "${webPath}/partner/accountDistrictList";
		        json_package = {
		            "head": {},
		            "body": {"accountId": accountId,"cityId":cityId,"isAll":isAll}
		        };
		        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
		            if (typeof result == 'string') result = JSON.parse(result);
		            if (result.body.result == '0') {
		                $("#districtList").empty();
			        	var list = result.body.list;
			        	var str = "";
			        	if(list.length<=0){
			        		return
			        	}
			        	for(var i=0;i<list.length;i++){
			        		str += '<option value="'+list[i].cityId+'">'+list[i].name+'</option>';
			        	}
			        	$("#districtList").append(str);
			        	console.log(list);
		            } else {
		                alert(result.body.description)
		            }
		        });
	        	
            } else {
                alert(result.body.description)
            }
        })
    }
    
    function cityChange(){
    	var cityId = $("#cityList").find("option:selected").val();
    	var isAll = $("#cityList").find("option:selected").attr("name");
    	var baseURL = "${webPath}/partner/accountDistrictList";
        var accountId = $("#accountId_hidden").val();
        var json_package = {
            "head": {},
            "body": {"accountId": accountId,"cityId":cityId,"isAll":isAll}
        };
        $.post(baseURL, {"json_package": JSON.stringify(json_package)}, function (result) {
            if (typeof result == 'string') result = JSON.parse(result);
            if (result.body.result == '0') {
                $("#districtList").empty();
	        	var list = result.body.list;
	        	var str = "";
	        	if(list.length<=0){
	        		return
	        	}
	        	for(var i=0;i<list.length;i++){
	        		str += '<option value="'+list[i].cityId+'">'+list[i].name+'</option>';
	        	}
	        	$("#districtList").append(str);
	        	console.log(list);
            } else {
                alert(result.body.description)
            }
        })
    }
    
    var deliver_goods = function () {
        var accountId = $("#accountId_hidden").val();
        var baseURL = "${webPath}/toModifyPartner/"+accountId;
        window.open(baseURL);
    };
    
    function delUser(r) {
        $("table").index($(r).parent().parent());
        $(r).parent().parent().remove();
    }
</script>
</body>
</html>
